package com.qingke.project_management.command_impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.qingke.project_management.App;
import com.qingke.project_management.Console;
import com.qingke.project_management.IDao.UserMapper;
import com.qingke.project_management.command.Command;
import com.qingke.project_management.pojo.User;

public class ListCommand extends Command {

	public void execute() {
		
		if(App.getInstance().getUser()==null){
			Console.println("您还未登录，没有权限执行该操作");
			return;
		}
		
		
		boolean doit = true;
		while(doit){
			Console.println("请输入要浏览的内容:");
			Console.println("【1】查看用户（实现）");
			Console.println("【2】查看项目");
			Console.println("【3】查看材料");
			int choice = Console.askInputInt("要查看的选项");
			switch (choice) {
			case 1:
				listAllUsers();
				doit = false;
				break;
			case 2:
				listAllProjects();
				doit = false;
				break;
			case 3:
				listAllMaterials();
				doit = false;
				break;
			default:
				Console.println("命令不正确");
				break;
			}
		}
		
		
	}
	
	private void listAllMaterials() {
		System.out.println("这是一个付费功能,充值才能变更强");
	}

	private void listAllProjects() {
		//其实是这几个方法功能类似 懒得写了
		System.out.println("这是一个付费功能,充值才能变更强");
	}

	private void listAllUsers(){
		System.out.println("==========所有用户==========");
		List<User> users = null;
		SqlSession session = getSession();
		UserMapper userMapper = session.getMapper(UserMapper.class);
		users = userMapper.selectAllUsers();
		int i=1;
		for (User user : users) {
			Console.print("User"+(i++));
			Console.println(user);
		}
	}
}
